package com.bw.risk.timed;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bw.core.creditStatus.OrderStatus;
import com.bw.risk.mapper.TbRiskOrderMapper;
import com.bw.risk.pojo.TbRiskOrder;
import com.bw.risk.service.TbRiskOrderService;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * 定时任务
 */
@Configuration
@EnableScheduling
public class TimerTask {

    @Autowired
    private TbRiskOrderMapper riskOrderMapper;

    @Autowired
    private TbRiskOrderService riskOrderService;

    //定时任务:开始风控
    @Scheduled(cron = "* 0/5 * * * ? ")//定时任务:开始风控5分钟
    public void findList(){
        System.out.println("定时任务开始");
        //查询所有待审核的信息
        QueryWrapper<TbRiskOrder> riskOrderQueryWrapper = Wrappers.query();
        riskOrderQueryWrapper.eq("status",OrderStatus.ORDER_CHECK_NONE);
        List<TbRiskOrder> riskOrders = riskOrderMapper.selectList(riskOrderQueryWrapper);
        if (ObjectUtil.isEmpty(riskOrders)){
            return;
        }
        for (TbRiskOrder riskOrder : riskOrders) {
            riskOrderService.riskSystem(riskOrder);
        }
    }
}